// 最大数

package Leetcode;

import java.util.Arrays;
import java.util.Comparator;

class Solution179 {
    public String largestNumber(int[] nums) {
        Integer[] integers = Arrays.stream(nums).boxed().toArray(Integer[]::new);
        Arrays.sort(integers, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                String s1 = o1.toString();
                String s2 = o2.toString();
                return -(s1 + s2).compareTo(s2 + s1);
            }
        });
        // 如果第一个是0则代表是一个全为0的nums
        if (integers[0] == 0)
            return "0";

        StringBuilder result = new StringBuilder();
        for (Integer i : integers) {
            result.append(i);
        }
        return result.toString();
    }
}